﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AIS.SDK.Model;
using Newtonsoft.Json;

namespace AIS.SDK.Model
{
 
    public class QueryConditionCollection : List<condition>
    {
        public QueryConditionCollection()
            : base()
        {
        }

        public QueryConditionCollection(IEnumerable<condition> collection)
            : base(collection)
        {
        }

        public condition FindByFieldName(string fieldName)
        {
            foreach (condition con in this)
            {
                if (con.Fieldname.Equals(fieldName, StringComparison.OrdinalIgnoreCase))
                    return con;
            }
            return null;
        }

        public QueryConditionCollection FromJson(string jsonstr)
        {
            QueryConditionCollection conditions = new QueryConditionCollection();
            conditions.AddRange(JsonConvert.DeserializeObject<List<condition>>(jsonstr));
            return conditions;
        }
    }

}
